HAL CORTEX How to Use

group CORTEX_How_To_Use

CORTEX main features

The HAL CORTEX driver contains four main blocks:

  1. NVIC: Nested Vector Interrupt Controller

    • The NVIC is an embedded interrupt controller that supports low-latency interrupt processing.

      • It contains a configurable interrupt handling ability. Configured items can be:

        • Priority grouping that specifies the range of preemption priority and sub priority.

        • Preemption priority ability between interrupts.

        • Subpriority ability between interrupts.

  2. SYSTICK: System Timer

    • The SysTick is a 24-bit countdown timer. It can be used as a simple counter or as a tick timer in a real-time operating system (RTOS).

  3. MPU: Memory Protection Unit

    • The MPU allows privileged software to define memory regions, assign memory access permissions and memory attributes to each of them to improve the system reliability.

    • The MPU in this device supports 8 regions.

  4. SCB: System Control Block

    • The SCB provides system information and system control that includes configuration, control and reporting of system fault exceptions.

How to use the CORTEX HAL module driver

The CORTEX HAL driver can be used as follows:

This driver provides HAL_CORTEX driver functions to configure the NVIC, SYSTICK, MPU, and SCB blocks.

  1. How to configure NVIC interrupts using the CORTEX HAL driver:

    • Configure the NVIC priority grouping using the HAL_CORTEX_NVIC_SetPriorityGrouping() function once at startup.

      • When the HAL_CORTEX_NVIC_PRIORITY_GROUP_0 is selected, IRQ preemption is no longer configurable. The pending IRQ priority is managed only by the sub-priority.

      • When the HAL_CORTEX_NVIC_PRIORITY_GROUP_1 is selected, there is one bit for preemption priority and three bits for sub-priority.

      • When the HAL_CORTEX_NVIC_PRIORITY_GROUP_2 is selected, there are two bits for preemption priority and two bits for sub-priority.

      • When the HAL_CORTEX_NVIC_PRIORITY_GROUP_3 is selected, there are three bits for preemption priority and one bit for sub-priority.

      • When the HAL_CORTEX_NVIC_PRIORITY_GROUP_4 is selected, IRQ sub-priority is no longer configurable. The pending IRQ priority is managed only by the preemption priority.

    • Configure the priority of the selected IRQ channels using HAL_CORTEX_NVIC_SetPriority() function :

      • IRQ priority order (sorted by highest to lowest priority):

        • The lowest is the preemption priority numerical value, the highest is the preemption priority.

        • The lowest is the subpriority numerical value, the highest is the subpriority.

      • Get the priority grouping using HAL_CORTEX_NVIC_GetPriorityGrouping() function.

      • Get the priority of an interrupt using HAL_CORTEX_NVIC_GetPriority() function.

    • Enable the selected IRQ channels using HAL_CORTEX_NVIC_EnableIRQ() function.

    • Disable the selected IRQ channels using HAL_CORTEX_NVIC_DisableIRQ() function.

    • To check if an IRQ channel is enabled or not, use HAL_CORTEX_NVIC_IsEnabledIRQ() function.

    • To check if an IRQ channel is active or not, use HAL_CORTEX_NVIC_IsActiveIRQ() function.

    • To set pending bit of an interrupt, use HAL_CORTEX_NVIC_SetPendingIRQ() function.

    • To check if the IRQn channel is in pending state or not, use HAL_CORTEX_NVIC_IsPendingIRQ() function. When pending, use HAL_CORTEX_NVIC_ClearPendingIRQ() to clear the event.

    • When a system reset is needed within the application, use HAL_CORTEX_NVIC_SystemReset() function.

  2. How to configure SYSTICK using the CORTEX HAL driver:

  3. How to configure MPU using the CORTEX HAL driver:

  4. How to configure SCB using the CORTEX HAL driver: